package com.seaboxdata.jt809.kafka.serializer;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.seaboxdata.jt809.packet.JT809Packet0x1202;
import org.apache.kafka.common.serialization.Serializer;

import java.util.Map;

/**
 * @ClassName JT809Packet0x1202Serializer
 * @Description JT809Packet0x1202序列化类
 * @Author DFJX
 * @Company 北京东方金信科技有限公司
 * @Date 2020/7/21 9:16
 * Version 1.0
 **/
public class JT809Packet0x1202Serializer implements Serializer<JT809Packet0x1202> {
    @Override
    public void configure(Map map, boolean b) {

    }


    @Override
    public byte[] serialize(String s, JT809Packet0x1202 jt809Packet0x1202) {
        ObjectMapper objectMapper=new ObjectMapper();
        objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
        objectMapper.registerModule(new JavaTimeModule());
        byte[] retVal = null;
        try {
            jt809Packet0x1202.setVehicleNo(jt809Packet0x1202.getVehicleNo().replace("\\u0000",""));
            retVal=objectMapper.writeValueAsString(jt809Packet0x1202).getBytes();
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return retVal;
    }

    @Override
    public void close() {

    }
}
